package org.example.redis_concurrent.utils;

import java.util.Random;

public class RandomUtils {

    public static String genRandString(int length){
        String alphabetsInUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String alphabetsInLowerCase = "abcdefghijklmnopqrstuvwxyz";
        String numbers = "0123456789";
        // create a super set of all characters
        String allCharacters = alphabetsInLowerCase + alphabetsInUpperCase + numbers;
        // initialize a string to hold result
        StringBuffer randomString = new StringBuffer();
        // loop for 10 times
        for (int i = 0; i < length; i++) {
            // generate a random number between 0 and length of all characters
            int randomIndex = (int)(Math.random() * allCharacters.length());
            // retrieve character at index and add it to result
            randomString.append(allCharacters.charAt(randomIndex));
        }
        return randomString.toString();
    }

    public static long genRandLong(int length){
        String numbers = "0123456789";
        // create a super set of all characters
        String allCharacters = numbers;
        // initialize a string to hold result
        StringBuffer randomString = new StringBuffer();
        // loop for 10 times
        for (int i = 0; i < length; i++) {
            // generate a random number between 0 and length of all characters
            int randomIndex = (int)(Math.random() * allCharacters.length());
            // retrieve character at index and add it to result
            randomString.append(allCharacters.charAt(randomIndex));
        }
        return Long.parseLong(randomString.toString());
    }

    public static int genIntegerInRange(int min,int max) {
        Random rand = new Random();
        int number=rand.nextInt(max - min + 1) + min;
        return number;
    }
//62 100 76 96 80 66 67 10 55 16



    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            int result= genIntegerInRange(1,1000);
            System.out.println(result);
        }

    }



}
